package training.oop;

/**
 * Singleton is a design pattern that helps to make sure we just create only one
 * Object for a given class.
 * 
 * @author harinath
 * 
 */
public class Singleton {

	private static Singleton instance;

	/**
	 * Let us make the constructor private. Remember when constructor is private
	 * then you won't be able to create object with new operator. so you will be forced to 
	 * use the public static method (if exists). If you do not have static method to create object 
	 * then you will never be able to create object.
	 */
	private  Singleton() {

	}
	
	private Singleton(String name, int id){
		
	}

	public static Singleton getInstance() {
		if (instance == null) {
			System.out.println("instance is null so new object to be created");
			instance = new Singleton();
		}
		else{
			System.out.println("instance is not null so let us use exisitng one");
		}
		return instance;
	}

}
